//
let str: string = 'hello Webpack Ts';

//1. 类型的声明
type NameType = string;
let str2: NameType = 'i love you';

type Key = string | number;
let k: Key = 100;

type Person = {
  name: string,
  age: number,
}

type Persons = Person[];

let users: Persons = [{name:'张三', age :20}, {name: 'xxx', age: 18}];

//2. 获得某个变量的类型 JS typeof 
//获得 k 变量的类型, 然后赋值给 TY 类型
type TY = typeof k;

//将 k 的类型赋值给 t 变量
let t = typeof k;

type T = typeof users;

//3. 获取接口键名的联合类型
interface Book{
  id: number;
  title: string;
  price: number;
  author: string
}

// 'id' | 'title' | 'price' | 'author'
type T2 = keyof Book;

function getInfo(book: Book, name: T2){
  return book[name];
}

let book: Book = {
  id: 1,
  title: '水浒传',
  price: 12,
  author: '施耐庵'
}

getInfo(book, 'author');

//4. 获取函数返回值类型
export function add(a:number, b: number){
  return a + b;
}

export type RetType = ReturnType<typeof add>;

//5. 获取参数的类型
export type ParamsType = Parameters<typeof add>

export type add = string;

//暴露方式  
//1. 分别暴露
//2. 统一暴露
//3. 默认暴露

export default book;

